package com.chao.demo.utils.desensitization;

import cn.hutool.core.util.DesensitizedUtil;

import java.util.function.Function;
//脱敏策略
public enum DesensitizationStrategy {
    /**
     * 自定义邮箱脱敏接口
     */
    EMALI1(new Function<String, String>() {
        @Override
        public String apply(String s) {
            return DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.EMAIL);
        }
    }),
    PHONE(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.MOBILE_PHONE)),
    //身份证，保留前6位，其他使用*替换
    ID_CARD(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.ID_CARD)),
    //地址，保留前四位，其他使用*替换
    ADDRESS(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.ADDRESS)),
    PASSWORD(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.PASSWORD));

    private final java.util.function.Function<String, String> desensitizer;

    DesensitizationStrategy(java.util.function.Function<String, String> desensitizer) {
        this.desensitizer = desensitizer;
    }

    public String desensitize(String input) {
        return desensitizer.apply(input);
    }
}
